using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;

namespace UIWidgetsSample
{
    public class TableSample : UIWidgetsSamplePanel
    {
        protected override Widget createWidget()
        {
            return new MaterialApp(
                showPerformanceOverlay: false,
                home: new TableWidget());
        }

        protected override void OnEnable()
        {
            FontManager.instance.addFont(Resources.Load<Font>(path: "fonts/MaterialIcons-Regular"), "Material Icons");
            base.OnEnable();
        }
    }

    public class TableWidget : StatelessWidget
    {
        public TableWidget(Key key = null) : base(key)
        {
        }

        public override Widget build(BuildContext context)
        {
            List<TableRow> tableRows = new List<TableRow>();

            for (int i = 0; i < 10; i++)
            {
                tableRows.Add(
                    new TableRow(
                    decoration: (i % 2 == 0) ? null : new BoxDecoration(color: Colors.blue),
                    children: new List<Widget>()
                    {
                        new Text("Row" + i, textAlign: TextAlign.center),
                        new Text("Row")
                    }
                ));
            }


            return new Scaffold(
                body: new Table(
                    children: tableRows,
                    defaultVerticalAlignment: TableCellVerticalAlignment.middle));
        }
    }
}